package com.api.shopapi.mapper;

import com.api.shopapi.entity.Train;
import com.api.shopapi.entity.TrainRecord;
import com.api.shopapi.entity.dto.TrainDTO;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface TrainRecordMapper {

    @Insert("insert into train_record " +
            "(" +
            "trainRecordCode, " +
            "trainCode, " +
            "userCode, " +
            "governmentCode, " +
            "institutionCode, " +
            "CreateTime, " +
            "StartTime, " +
            "EndTime " +
            ") VALUES " +
            "(" +
            "#{trainRecord.trainRecordCode} ," +
            "#{trainRecord.trainCode} ," +
            "#{trainRecord.userCode} ," +
            "#{trainRecord.governmentCode} ," +
            "#{trainRecord.institutionCode} ," +
            "#{trainRecord.CreateTime} ," +
            "#{trainRecord.StartTime}, " +
            "#{trainRecord.EndTime}" +
            ") ")
    int insert(@Param("trainRecord") TrainRecord trainRecord);


    @Update("update train_record set " +
            "StartTime=#{train.StartTime}," +
            "EndTime=#{train.EndTime}" +
            " where trainRecordCode=#{trainRecord.trainRecordCode}      ")
    int update(@Param("trainRecord") TrainRecord trainRecord);


    @Select("select * from train_record where trainRecordCode=#{trainRecordCode} ")
    TrainRecord getByTrainRecordCode(@Param("trainRecordCode") String trainRecordCode);


    @Select("<script>" +
            "select  * from train_record" +
            " where GovernmentCode=#{governmentCode} " +
            "<if test ='startTime !=null and startTime!=\"\" and endTime !=null and endTime!=\"\" '>" +
            " and StartTime between #{startTime} and #{endTime}" +
            "</if>" +
            " order by CreateTime desc " +
            "</script>")
    List<TrainRecord> getPageList(@Param("governmentCode") String governmentCode,
                               @Param("startTime")String startTime,
                               @Param("endTime")String endTime);

}
